<template>
	<view class="u-page">
		<view class="u-demo-block">
			<view class="u-demo-block__content">
				<u--form labelPosition="left" :model="model1" ref="form1">
					<u-form-item label="钱包ID" labelWidth="100" prop="out_account" @click="disabled1 = true; hideKeyboard()" borderBottom ref="item1">
						<u--input v-model="model1.out_account" border="none" placeholder="请选择钱包ID"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="到账银行卡" labelWidth="100" prop="settle_bank" @click="showSex = true; hideKeyboard()" borderBottom ref="item1">
						<u--input v-model="model1.settle_bank" border="none" placeholder="请选择到账银行卡"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					
					<u-form-item label="提现金额" labelWidth="100" prop="amount" borderBottom ref="item1">
						<u--input type="number" v-model="model1.amount" border="none" placeholder="请输入提现金额"></u--input>
					</u-form-item>
					<u-form-item label="备注留言" labelWidth="100" prop="remark" borderBottom ref="item3" >
						<u--textarea
							placeholder="请输入备注留言(可为空)"
							v-model="model1.remark"
							count
						></u--textarea>
					</u-form-item>
				</u--form>
				<view class="" style="margin-top: 10rpx;">钱包余额：{{cash_amount.cash_amount||0}}</view>
				<u-button type="success" text="提交" customStyle="margin-top: 50px;height:50px;line-height:50px" @click="submit"></u-button>
				<view class="flex flex-align flex-end">
					<view class="" style="margin-top: 20rpx;" @click="goUrl">提现记录</view>
				</view>
				<u-action-sheet :show="showSex" :actions="fileList1" title="请选择到账银行卡" description="" @close="showSex = false" @select="sexSelect">
				</u-action-sheet>
				<u-action-sheet :show="disabled1" :actions="walletinfo" title="请选择钱包ID" description="" @close="disabled1 = false" @select="walletSelect">
				</u-action-sheet>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
				walletinfo:[],
				disabled1: false,
				tips: '',
				value: '',
				showCalendar: false,
				showBirthday: false,
				model1: {
					out_account:'',
					settle_bank:'',
					amount:'',
					remark:''
				},
				showSex: false,
				cash_amount:''
				
			}
		},
		onReady() {
			// 如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则
		},
		onLoad() {
			
			this.getWallet()
		},
		methods: {
			getBank(){
				let that = this
				that.tui.request("fund.withdrawal/getWithdrawalBankList", "POST", {agent_account_id:that.cash_amount.agent_account_id}, false, false, true).then((res) => {
					if(res.code==1){
						that.fileList1 = res.data.list
						that.fileList1.map((item,index)=>{
							item.name = item.account_card_no
						})
					}
				}).catch((res) => {
					
				})
			},
			goUrl(){
				this.tui.href('/pages/tixian/tixianList')
			},
			getWallet(){
				let that = this
				that.tui.request("fund.wallet/getWalletList", "POST", {}, false, false, true).then((res) => {
					if(res.code==1){
						that.walletinfo = res.data.list
						that.walletinfo.map((item,index)=>{
							item.name = item.account_name +'('+item.agent_account_id+')'
						})
					}
				}).catch((res) => {
					
				})
			},
			navigateBack() {
				uni.navigateBack()
			},
			sexSelect(e) {
				this.model1.settle_bank = e.account_card_no
			},
			walletSelect(e){
				this.model1.out_account = e.agent_account_id
				this.cash_amount = e
				this.getBank()
			},
			change(e) {
				// console.log(e);
			},
			submit() {
				let that = this
				that.tui.request("fund.withdrawal/doWithdrawalBank", "POST", that.model1, false, false, true).then((res) => {
					if(res.code==1){
						setTimeout(() => {
							that.reset()
						}, 10)
					}
				}).catch((res) => {
					
				})
			},
			
			reset() {
				const validateList = ['out_account', 'settle_bank', 'amount', 'remark']
				this.$refs.form1.resetFields()
				this.$refs.form1.clearValidate()
				setTimeout(() => {
					this.$refs.form1.clearValidate(validateList)
					// 或者使用 this.$refs.form1.clearValidate()
				}, 10)
			},
			hideKeyboard() {
				uni.hideKeyboard()
			}
		},
	}
</script>

<style lang="scss">
	.u-demo-block{padding: 20rpx 30rpx;}
</style>